package com.zt.questionnaire.common.config;

import com.zt.questionnaire.common.utils.SystemUtils;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.net.SocketException;

@ConfigurationProperties(prefix = "server")
@Data
public class AppServerConfig {
    private static final Logger log = LoggerFactory.getLogger(AppServerConfig.class);

    private String contextPath;
    private int port;
    private String tag;
    private String industry;
    private String hostIp;

    public AppServerConfig() {
        this.tag = System.getProperty("tag");
        this.industry = System.getProperty("industry");
        try {
            this.hostIp = SystemUtils.getLanIp();
        } catch (SocketException e) {
            log.error(e.getMessage(), e);
        }
    }

    public String getServiceName() {
        if (this.contextPath != null) {
            return this.contextPath.substring(1);
        }
        return null;
    }


}
